package com.erp.module.packPiece

import android.content.Context
import com.erp.bean.PackPieceBean
import com.erp.contacts.Contacts
import com.erp.contacts.Contacts.BOUNDARY
import com.erp.Interface.OnUserDataInterface
import com.erp.util.Httputil
import org.xutils.http.RequestParams
import org.xutils.x

/**
 * Created by Administrator on 2018/12/14/014.
 * 作者：刘洋
 */
class PackPieceM : PackPieceContract.PackPieceMP {
    override fun getPackPiece(context: Context, page: Int, pagesize: Int, sousuo : FragmentPackPiece.SousuoBean, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.PACK_PIECE)
        Httputil.getparams(context, params)
        params.addBodyParameter("page", page.toString())
        params.addBodyParameter("pagesize", pagesize.toString())
        params.addBodyParameter("searchParams[work_staff_id]", sousuo.name_id)
        if(sousuo.start_time!=""&&sousuo.end_time!=""){
            params.addBodyParameter("searchParams[time_filter][time_category]", sousuo.time_category)
            params.addBodyParameter("searchParams[time_filter][start_time]", sousuo.start_time)
            params.addBodyParameter("searchParams[time_filter][end_time]", sousuo.end_time)
        }
        x.http().get(params, Httputil.Call(context, onUserDataInterface))
    }

    override fun putPackPiece(context: Context,work_staff_id :  String, beans: MutableList<PackPieceBean>, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.PACK_PIECE)
        Httputil.getparams(context, params)
        Httputil.addtoken(params)
        params.addBodyParameter("work_staff_id", work_staff_id, BOUNDARY)
        for (i in 0 until beans.size){
            val b = beans[i]
            params.addBodyParameter("packpiece[$i][batch_name]", b.batch_name, BOUNDARY)
            params.addBodyParameter("packpiece[$i][cid]",b.cid,BOUNDARY)
            params.addBodyParameter("packpiece[$i][gangwei_id]",b.gangwei_id,BOUNDARY)
        }
        x.http().post(params, Httputil.Call(context, onUserDataInterface))
    }
}